# 对象层
from selenium.webdriver.common.by import By
from V5.utils import UtilsDriver

class PageLogin:
    def __init__(self):
        self.driver=UtilsDriver().get_driver()
        self.username=By.ID,"username"
        self.password=By.ID,"password"
        self.code=By.CSS_SELECTOR,"[class='text_uspa check_cum']>[class='text_cmu']"
        self.login=By.CSS_SELECTOR,".J-login-submit"

    def find_username(self):
        return self.driver.find_element(*self.username)

    def find_password(self):
        return self.driver.find_element(*self.password)

    def find_code(self):
        return self.driver.find_element(*self.code)

    def find_login_btn(self):
        return self.driver.find_element(*self.login)

# 操作层
class HandleLogin:
    def __init__(self):
        self.page_login=PageLogin()

    def handle_username(self,username):
        self.page_login.find_username().clear()
        self.page_login.find_username().send_keys(username)

    def handle_password(self,password):
        self.page_login.find_password().clear()
        self.page_login.find_password().send_keys(password)

    def handle_code(self,code):
        self.page_login.find_code().clear()
        self.page_login.find_code().send_keys(code)

    def handle_login_btn(self):
        self.page_login.find_login_btn().click()

# 业务层
class ProxyLogin:
    def __init__(self):
        self.handle_login=HandleLogin()

    def login_page(self,username,password,code):
        self.handle_login.handle_username(username)
        self.handle_login.handle_password(password)
        self.handle_login.handle_code(code)
        self.handle_login.handle_login_btn()